package com.hq.door.controller;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.hq.door.dto.ClassInfo;
import com.hq.door.dto.DClass;
import com.hq.door.dto.DClassDto;
import com.hq.door.dto.StudentInfo;
import com.hq.door.dto.Teacher;
import com.hq.door.pojo.TClass;
import com.hq.door.service.TClassService;
import com.hq.door.service.TTeacherService;

@Controller
@RequestMapping("/tclass")
public class TClassController {
	@Autowired
	private TClassService tClassService;
	@Autowired
	private TTeacherService tTeacherService;
	
	//加入班级
	@RequestMapping("/addclass")
	@ResponseBody
	public int add(DClass dClass) {
		tClassService.saveclass(dClass);
		return 1;
	}

	//删除班级
	@RequestMapping("/deleteclass")
	@ResponseBody
	public int delete(int[] id) {
		tClassService.deleteselect(id);
		return 1;
	}
	
	@RequestMapping("/getOneClass")
	@ResponseBody
	public Object getOneClass(@RequestParam(value = "code", required = true) String code) {
		System.out.println("请求到来"+code);
		DClass classInfo = null;

		classInfo = tClassService.getOneClass(code);
		
		return classInfo;
	}



	//修改
	@RequestMapping("/updateclass")
	@ResponseBody
	public int updateclass(TClass tClass) {
		TClass tClass2 = tClassService.get(tClass.getId());
		if (tClass2 != null) {
			tClass.setId(tClass2.getId());
			tClass.setModifiedTime(new Timestamp(System.currentTimeMillis()));
			tClass.setModifiedBy(tClass2.getModifiedBy() + 1);
			tClassService.update(tClass);
		} else {
			tClassService.save(tClass);
		}
		return 1;
	}

	
	@RequestMapping("/getByPage")
	@ResponseBody
	public Object getByPage(
			@RequestParam(value = "type", required = true) Integer type,
			@RequestParam(value = "para", required = false) String para,
			@RequestParam(value = "pageSize", required = false) Integer pageSize,
			@RequestParam(value = "pageStart", required = false) Integer pageStart) {

		List<DClass> dClasses = null;

		if (pageSize != null && pageStart != null) {
			if (para == null)
				para = "";
			dClasses = tClassService.getByPage(type, para, pageStart, pageSize);
		} else {
			if (para == null)
				para = "";
			return tClassService.getCount(type, para);
		}
		return dClasses;

	}
	@RequestMapping("/getcount")
	@ResponseBody
	public Object getCount(int type,String para){
		return tClassService.getCount(type, para);
	}
	
	@RequestMapping("/getTeacher")
	@ResponseBody
	public List<String> getteacher(){
		List<String> list = tTeacherService.getTeacher();
//		for (int i = 0; i < list.size(); i++) {
//			System.out.println("list----------------------"+list.get(i));
//		}
		return list;
	}
	
}
